package com.mate.cloud.user.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.Maps;
import com.mate.cloud.enums.CommonEnum;

import java.util.Map;

/**
 * 性别枚举 1:男、2: 女
 *
 * @author cong zhi
 * @email 448341911@qq.com
 * @createDate 2023/3/3 11:29
 * @version: v1.0
 */
public enum GenderEnum implements CommonEnum {
    /**
     * 性别: 1 男
     */
    MAN(1, "男"),
    /**
     * 性别: 2 女
     */
    WOMAN(2, "女");

    /**
     * 在对应的Enum属性上添加@EnumValue注解
     */
    @EnumValue
    /**标记响应json值*/
    @JsonValue
    private final int code;

    private final String desc;

    GenderEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, GenderEnum> VALUES = Maps.newHashMap();

    static {
        for (final GenderEnum gender : GenderEnum.values()) {
            GenderEnum.VALUES.put(gender.getCode(), gender);
        }
    }

    @Override
    public String getDescription() {
        return this.desc;
    }

    @Override
    public int getCode() {
        return this.code;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public GenderEnum valueOf(int code) {
        return VALUES.get(code);
    }

}
